/*     */ package com.zimbra.cs.account;
/*     */ 
/*     */ import com.google.common.collect.Sets;
/*     */ import com.zimbra.common.account.Key.ServerBy;
/*     */ import com.zimbra.common.account.ZAttrProvisioning.DistributionListSubscriptionPolicy;
/*     */ import com.zimbra.common.account.ZAttrProvisioning.DistributionListUnsubscriptionPolicy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.account.accesscontrol.ACLUtil;
/*     */ import com.zimbra.cs.account.accesscontrol.GranteeType;
/*     */ import com.zimbra.cs.account.accesscontrol.Right;
/*     */ import com.zimbra.cs.account.accesscontrol.Rights.User;
/*     */ import com.zimbra.cs.account.accesscontrol.ZimbraACE;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Collection;
/*     */ import java.util.Collections;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public abstract class Group
/*     */   extends MailTarget
/*     */   implements AliasedEntry
/*     */ {
/*  44 */   public static final ZAttrProvisioning.DistributionListSubscriptionPolicy DEFAULT_SUBSCRIPTION_POLICY = ZAttrProvisioning.DistributionListSubscriptionPolicy.REJECT;
/*     */   
/*     */ 
/*  47 */   public static final ZAttrProvisioning.DistributionListUnsubscriptionPolicy DEFAULT_UNSUBSCRIPTION_POLICY = ZAttrProvisioning.DistributionListUnsubscriptionPolicy.REJECT;
/*     */   
/*     */   public Group(String name, String id, Map<String, Object> attrs, Provisioning prov) {
/*  50 */     super(name, id, attrs, null, prov);
/*     */   }
/*     */   
/*     */ 
/*     */   public abstract boolean isDynamic();
/*     */   
/*     */   public abstract Domain getDomain()
/*     */     throws ServiceException;
/*     */   
/*     */   public abstract String[] getAllMembers()
/*     */     throws ServiceException;
/*     */   
/*     */   public abstract Set<String> getAllMembersSet()
/*     */     throws ServiceException;
/*     */   
/*     */   public abstract String getDisplayName();
/*     */   
/*     */   public abstract String getMail();
/*     */   
/*     */   public abstract boolean isPrefReplyToEnabled();
/*     */   
/*     */   public abstract String getPrefReplyToAddress();
/*     */   
/*     */   public abstract String getPrefReplyToDisplay();
/*     */   
/*     */   public abstract ZAttrProvisioning.DistributionListSubscriptionPolicy getDistributionListSubscriptionPolicy();
/*     */   
/*     */   public abstract ZAttrProvisioning.DistributionListUnsubscriptionPolicy getDistributionListUnsubscriptionPolicy();
/*     */   
/*     */   public boolean hideInGal()
/*     */   {
/*  81 */     String hideInGal = getAttr("zimbraHideInGal");
/*  82 */     return "TRUE".equals(hideInGal);
/*     */   }
/*     */   
/*     */   public Server getServer() throws ServiceException {
/*  86 */     String serverName = getAttr("zimbraMailHost");
/*  87 */     return serverName == null ? null : getProvisioning().get(Key.ServerBy.name, serverName);
/*     */   }
/*     */   
/*     */   public boolean isMemberOf(Account acct) throws ServiceException {
/*  91 */     return getProvisioning().inACLGroup(acct, getId());
/*     */   }
/*     */   
/*     */   public ZAttrProvisioning.DistributionListSubscriptionPolicy getSubscriptionPolicy() {
/*  95 */     ZAttrProvisioning.DistributionListSubscriptionPolicy policy = getDistributionListSubscriptionPolicy();
/*  96 */     if (policy == null) {
/*  97 */       return DEFAULT_SUBSCRIPTION_POLICY;
/*     */     }
/*  99 */     return policy;
/*     */   }
/*     */   
/*     */   public ZAttrProvisioning.DistributionListUnsubscriptionPolicy getUnsubscriptionPolicy()
/*     */   {
/* 104 */     ZAttrProvisioning.DistributionListUnsubscriptionPolicy policy = getDistributionListUnsubscriptionPolicy();
/* 105 */     if (policy == null) {
/* 106 */       return DEFAULT_UNSUBSCRIPTION_POLICY;
/*     */     }
/* 108 */     return policy;
/*     */   }
/*     */   
/*     */ 
/*     */   public boolean isAddrOfEntry(String addr)
/*     */   {
/* 114 */     addr = addr.toLowerCase();
/* 115 */     if (getName().equals(addr)) {
/* 116 */       return true;
/*     */     }
/* 118 */     Set<String> aliases = getMultiAttrSet("zimbraMailAlias");
/* 119 */     return aliases.contains(addr);
/*     */   }
/*     */   
/*     */ 
/*     */   public Set<String> getAllAddrsSet()
/*     */   {
/* 125 */     Set<String> addrs = Sets.newHashSet();
/* 126 */     addrs.add(getName());
/* 127 */     addrs.addAll(getMultiAttrSet("zimbraMailAlias"));
/* 128 */     return Collections.unmodifiableSet(addrs);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static class GroupOwner
/*     */   {
/* 141 */     public static Right GROUP_OWNER_RIGHT = Rights.User.R_ownDistList;
/*     */     private final GranteeType type;
/*     */     private final String id;
/*     */     private String name;
/*     */     
/*     */     private GroupOwner(ZimbraACE ace, boolean needName)
/*     */     {
/* 148 */       this.type = ace.getGranteeType();
/* 149 */       this.id = ace.getGrantee();
/* 150 */       if (needName) {
/* 151 */         this.name = ace.getGranteeDisplayName();
/*     */       }
/*     */     }
/*     */     
/*     */     public GranteeType getType() {
/* 156 */       return this.type;
/*     */     }
/*     */     
/*     */     public String getId() {
/* 160 */       return this.id;
/*     */     }
/*     */     
/*     */     public String getName() {
/* 164 */       return this.name;
/*     */     }
/*     */     
/*     */     public static Set<Group> getOwnedGroups(Account acct) throws ServiceException
/*     */     {
/* 169 */       AccessManager accessMgr = AccessManager.getInstance();
/*     */       
/* 171 */       Right right = GROUP_OWNER_RIGHT;
/* 172 */       Map<Right, Set<Entry>> discoveredRights = accessMgr.discoverUserRights(acct, Collections.singleton(right), true);
/*     */       
/*     */ 
/* 175 */       Set<Entry> ownerOf = (Set)discoveredRights.get(right);
/* 176 */       Set<Group> ownerOfGroups = Sets.newHashSet();
/*     */       
/* 178 */       if (ownerOf != null) {
/* 179 */         for (Entry entry : ownerOf) {
/* 180 */           if ((entry instanceof Group))
/*     */           {
/*     */ 
/*     */ 
/*     */ 
/* 185 */             ownerOfGroups.add((Group)entry);
/*     */           }
/*     */         }
/*     */       }
/* 189 */       return ownerOfGroups;
/*     */     }
/*     */     
/*     */     public static Set<String> getOwnedGroupsIds(Account acct) throws ServiceException {
/* 193 */       Set<Group> groups = getOwnedGroups(acct);
/*     */       
/* 195 */       Set<String> ids = Sets.newHashSet();
/* 196 */       if (groups != null) {
/* 197 */         for (Group group : groups) {
/* 198 */           ids.add(group.getId());
/*     */         }
/*     */       }
/*     */       
/* 202 */       return ids;
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */     public static boolean isOwner(Account acct, Group group)
/*     */       throws ServiceException
/*     */     {
/* 211 */       return AccessManager.getInstance().canAccessGroup(acct, group, false);
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */     public static boolean hasOwnerPrivilege(Account acct, Group group)
/*     */       throws ServiceException
/*     */     {
/* 221 */       return AccessManager.getInstance().canAccessGroup(acct, group, true);
/*     */     }
/*     */     
/*     */     public static List<GroupOwner> getOwners(Group group, boolean needName) throws ServiceException
/*     */     {
/* 226 */       List<GroupOwner> owners = new ArrayList();
/*     */       
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 232 */       List<ZimbraACE> acl = ACLUtil.getAllACEs(group);
/* 233 */       if (acl != null) {
/* 234 */         for (ZimbraACE ace : acl) {
/* 235 */           Right right = ace.getRight();
/* 236 */           if (GROUP_OWNER_RIGHT == right) {
/* 237 */             owners.add(new GroupOwner(ace, needName));
/*     */           }
/*     */         }
/*     */       }
/*     */       
/* 242 */       return owners;
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */     public static void getOwnerEmails(Group group, Collection<String> result)
/*     */       throws ServiceException
/*     */     {
/* 251 */       List<ZimbraACE> acl = ACLUtil.getACEs(group, Collections.singleton(GROUP_OWNER_RIGHT));
/* 252 */       if (acl != null) {
/* 253 */         for (ZimbraACE ace : acl) {
/* 254 */           Right right = ace.getRight();
/* 255 */           result.add(ace.getGranteeDisplayName());
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/Group.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */